package com.ruoyi.voucher.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.TbDetails;
import com.ruoyi.voucher.service.ITbDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 明细账Controller
 *
 * @author ruoyi
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/details")
public class TbDetailsController extends BaseController {
    @Autowired
    private ITbDetailsService tbDetailsService;

    /**
     * 查询明细账列表
     */
    @RequiresPermissions("system:details:list")
    @GetMapping("/list")
    public TableDataInfo list(TbDetails tbDetails) {
        startPage();
        List<TbDetails> list = tbDetailsService.selectTbDetailsList(tbDetails);
        return getDataTable(list);
    }

    /**
     * 导出明细账列表
     */
    @RequiresPermissions("system:details:export")
    @Log(title = "明细账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDetails tbDetails) {
        List<TbDetails> list = tbDetailsService.selectTbDetailsList(tbDetails);
        ExcelUtil<TbDetails> util = new ExcelUtil<TbDetails>(TbDetails.class);
        util.exportExcel(response, list, "明细账数据");
    }

    /**
     * 获取明细账详细信息
     */
    @RequiresPermissions("system:details:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbDetailsService.selectTbDetailsById(id));
    }

    /**
     * 新增明细账
     */
    @RequiresPermissions("system:details:add")
    @Log(title = "明细账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDetails tbDetails) {
        return toAjax(tbDetailsService.insertTbDetails(tbDetails));
    }

    /**
     * 修改明细账
     */
    @RequiresPermissions("system:details:edit")
    @Log(title = "明细账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDetails tbDetails) {
        return toAjax(tbDetailsService.updateTbDetails(tbDetails));
    }

    /**
     * 删除明细账
     */
    @RequiresPermissions("system:details:remove")
    @Log(title = "明细账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbDetailsService.deleteTbDetailsByIds(ids));
    }

    @GetMapping("/deleteList")
    public R deleteList(Integer id) {
        return tbDetailsService.deketeList(id);
    }
}

/**/
